package com.chenu.gamscriptman.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Arrays;
import java.util.List;

@Data
@Accessors(chain = true)
@TableName(value = "device")
@ApiModel(value = "设备对象", description = "封装一个设备的信息，用于描述一个唯一的设备")    /* 这是一个API调用需要用到的参数 */
public class Device {

    @TableId(type = IdType.AUTO, value = "id")
    @ApiModelProperty(value = "id", name = "id", required = false, dataType = "long", example = "3")
    private Long id;

    @TableField(value = "group_nr")
    @ApiModelProperty(hidden = true)
    private String groupNr;     /* 这个分组号是内部组织的，不发给用户，转化为json时不需要加入，需要转换 */

    @TableField(value = "dev_nr")
    @ApiModelProperty(hidden = true)
    private Long devNr;         /* 这个设备号是内部组织的，不发给用户，转化为json时不需要加入，需要转换 */

    @TableField(value = "name")
    @ApiModelProperty(value = "设备名称", name = "name", required = false, dataType = "string", example = "XiaoMi 9")
    private String name;

    @TableField(value = "sys_version")
    @ApiModelProperty(value = "搭载系统版本", name = "sysVersion", required = false, dataType = "string", example = "Android 9.0")
    private String sysVersion;

    @TableField(value = "mac")
    @ApiModelProperty(value = "物理地址", name = "mac", required = false, dataType = "string", example = "")
    private String mac;

    @TableField(value = "storage")
    @ApiModelProperty(value = "存储空间", name = "storage", required = false, dataType = "string", example = "剩余容量47.3G/总容量59.6G")
    private String storage;

    @TableField(value = "intranet_ip")
    @ApiModelProperty(value = "内网IP", name = "intranetIp", required = false, dataType = "string", example = "192.168.0.1")
    private String intranetIp;

    @TableField(value = "extranet_ip")
    @ApiModelProperty(value = "外网IP", name = "extranetIp", required = false, dataType = "string", example = "179.0.0.1")
    private String extranetIp;

    @TableField(value = "battery")
    @ApiModelProperty(value = "电池状态信息", name = "battery", required = false,
            dataType = "string", example = "正在充电/59")
    private String battery;

    @TableField(value = "net_type")
    @ApiModelProperty(value = "网络类型", name = "netType", required = false,
            dataType = "string", example = "wifi")
    private String netType;

    @TableField(value = "memory")
    @ApiModelProperty(value = "内存空间", name = "memory", required = false,
            dataType = "string", example = "7.8G/15.9G")
    private String memory;

    @TableField(value = "uuid")
    @ApiModelProperty(value = "给设备分配的uuid，需要注意的是，如果生成的uuid带-字符，请先将它们去除", name = "uuid",
            required = false, dataType = "string", example = "157e94154f45492c80eb291b3b4422b0")
    private String uuid;

    @TableField(value = "imei")
    @ApiModelProperty(value = "设备IMEI标识码", name = "imei", required = false,
            dataType = "string", example = "861675041868180")
    private String imei;

    @TableField(value = "serial_nr")
    @ApiModelProperty(value = "设备序列号", name = "serialNr", required = false,
            dataType = "string", example = "a45das8d4wa1d2")
    private String serialNr;

    @TableField(value = "model")
    @ApiModelProperty(value = "设备型号", name = "model", required = false,
            dataType = "string", example = "Xiao Mi")
    private String model;

    @TableField(value = "nr_same_ip")
    @ApiModelProperty(value = "相同内网IP的设备数量，不必手动填写，系统自动检测生成。", name = "nrSameIp",
            required = false, dataType = "int", example = "1")
    private Integer nrSameIp;

    @TableField(value = "run_game")
    @ApiModelProperty(value = "设备运行的游戏名，不必手动填写，由系统自动检测生成", name = "runGame",
            required = false, dataType = "string", example = "一起来捉妖")
    private String runGame;

    @TableField(value = "exten_string")
    @ApiModelProperty(value = "拓展字符串，存放用户一些自己的字符串值。",
            name = "extenString", required = false, dataType = "string", example = "明天就放假了。")
    private String extenString;

    @TableField(value = "exten_int")
    @ApiModelProperty(value = "拓展数值型，存放用户一些自己的数字值。",
            name = "extenInt", required = false, dataType = "int", example = "666")
    private Integer extenInt;

    @TableField(value = "uptime")
    @ApiModelProperty(value = "设备更新时间（时间戳形式），不必手动填写，由系统自动检测生成",
            name = "uptime", required = false , dataType = "long", example = "1577455110")
    private Long uptime;

    @TableField(value = "admin_fk")
    @ApiModelProperty(hidden = true)
    private Long adminFk;

    /* 外键映射 */
    @TableField(exist = false)
    @ApiModelProperty(hidden = true)
    private User admin;

    /* 给用户的json数据需要忽略的字段 */
    public static List<String> ignoreAttr = Arrays.asList(
            "groupNr", "devNr", "adminFk", "admin",
            "devNrEnd", "noGroupNr", "groupNrs"
    );

    /* 额外的查询条件封装 */
    @TableField(exist = false)
    @ApiModelProperty(hidden = true)
    Long devNrEnd;          /* 设备编号结束 */

    /* 用户需要的数据，它们跟表中稍有不同 */
    @TableField(exist = false)
    @ApiModelProperty(value = "设备号，可以添加分组，分组号支持26个字母，格式：分组号 + 次设备号，分组号不给等于在默认分组，即不分组",
            name = "sdevNr", required = false, dataType = "string", example = "P7")
    String sdevNr;                  /* 提供给用户的设备号，它 = "分组号" + "设备号" */
    @TableField(exist = false)
    @ApiModelProperty(value = "设备的管理员（用户名），不必手动填写，由系统自动检测生成",
            name = "adminUsername", required = false, dataType = "string", example = "root")
    private String adminUsername;   /* 用户看不懂外键，他需要知道管理员的用户名是什么 */


    /* 支持的设备分组号 */
    public static String noGroupNr = ">";    /* 不分组 */
    public static List<String> groupNrs = Arrays.asList(
            noGroupNr,
            "A", "B", "C", "D", "E", "F",
            "G", "H", "I", "J", "K", "L",
            "M", "N", "O", "P", "Q", "R",
            "S", "T", "W", "X", "Y", "Z"
    );

}